<?php

namespace app\api\controller;
use app\common\controller\Api;
use app\common\model\MoneyLog;
use app\common\model\UserWithdrawApply;

/**
 * 佣金明细
 */
class Usermoney extends Api
{
    /**
     * MoneyLog模型对象
     * @var \app\common\model\MoneyLog
     */
    protected $model = null;
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new MoneyLog();
    }

    public function index(){
        $sta_time = input('sta_time');
        $end_time = input('end_time');
        $current  = input('current');
        $query    = $this->model->where(['user_id'=>$this->auth->id]);
        if($current == 0){
            $query = $query->where('money','>',0);
        }else{
            $query = $query->where('money','<',0);
        }
        if($sta_time && $end_time){
            $sta_time = strtotime($sta_time.' 00:00:01');
            $end_time = strtotime($end_time.' 23:59:59');
            $query = $query->where('createtime','between time',[$sta_time,$end_time]);
        }
        $data = $query->order('id desc')->paginate();
        $weidakuan = UserWithdrawApply::where(['status'=>1,'user_id'=>$this->auth->id])->sum('money');//待打款

        $this->success('ok',['data'=>$data,'all_money'=>$this->auth->money,'weidakuan'=>$weidakuan,'withdraw_money'=>$this->auth->withdraw_money]);
    }

}
